home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / PLOT.H < prev    next >
C/C++ Source or Header  |  1992-03-25  |  13KB  |  485 lines

  1. /*
  2.  * $Id: plot.h,v 3.26 92/03/24 22:34:13 woo Exp Locker: woo $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - plot.h */
  7. /*
  8.  * Copyright (C) 1986, 1987, 1990, 1991, 1992   Thomas Williams, Colin Kelley
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software is provided "as is" without express or implied warranty.
  21.  * 
  22.  *
  23.  * AUTHORS
  24.  * 
  25.  *   Original Software:
  26.  *     Thomas Williams,  Colin Kelley.
  27.  * 
  28.  *   Gnuplot 2.0 additions:
  29.  *       Russell Lang, Dave Kotz, John Campbell.
  30.  *
  31.  *   Gnuplot 3.0 additions:
  32.  *       Gershon Elber and many others.
  33.  * 
  34.  * Send your comments or suggestions to 
  35.  *  info-gnuplot@ames.arc.nasa.gov.
  36.  * This is a mailing list; to join it send a note to 
  37.  *  info-gnuplot-request@ames.arc.nasa.gov.  
  38.  * Send bug reports to
  39.  *  bug-gnuplot@ames.arc.nasa.gov.
  40.  */
  41.  
  42. #define PROGRAM "G N U P L O T"
  43. #define PROMPT "gnuplot> "
  44. #if defined(AMIGA_LC_5_1) || defined(AMIGA_AC_5)
  45. #define SHELL "NewShell"
  46. #else /* AMIGA */
  47. #define SHELL "/bin/sh"        /* used if SHELL env variable not set */
  48. #endif /* AMIGA  */
  49.  
  50. #define SAMPLES 100        /* default number of samples for a plot */
  51. #define ISO_SAMPLES 10        /* default number of isolines per splot */
  52. #define ZERO    1e-8        /* default for 'zero' set option */
  53.  
  54. #ifndef TERM
  55. /* default terminal is "unknown"; but see init_terminal */
  56. #define TERM "unknown"
  57. #endif
  58.  
  59. #define TRUE 1
  60. #define FALSE 0
  61.  
  62.  
  63. #define Pi 3.141592653589793
  64. #define DEG2RAD (Pi / 180.0)
  65.  
  66.  
  67. #define MIN_CRV_POINTS 100        /* minimum size of points[] in curve_points */
  68. #define MIN_SRF_POINTS 1000        /* minimum size of points[] in surface_points */
  69.  
  70. #define MAX_LINE_LEN 1024    /* maximum number of chars allowed on line */
  71. #define MAX_TOKENS 200
  72. #define MAX_ID_LEN 50        /* max length of an identifier */
  73.  
  74.  
  75. #define MAX_AT_LEN 150        /* max number of entries in action table */
  76. #define STACK_DEPTH 100
  77. #define NO_CARET (-1)
  78.  
  79.  
  80. #define MAX_NUM_VAR    2    /* Ploting projection of func. of max. two vars. */
  81.  
  82. #define MAP3D_CARTESIAN        0    /* 3D Data mapping. */
  83. #define MAP3D_SPHERICAL        1
  84. #define MAP3D_CYLINDRICAL    2
  85.  
  86. #define CONTOUR_NONE    0    /* Where to place contour maps if at all. */
  87. #define CONTOUR_BASE    1
  88. #define CONTOUR_SRF    2
  89. #define CONTOUR_BOTH    3
  90.  
  91. #define CONTOUR_KIND_LINEAR    0 /* See contour.h in contours subdirectory. */
  92. #define CONTOUR_KIND_CUBIC_SPL    1
  93. #define CONTOUR_KIND_BSPLINE    2
  94.  
  95. #define ANGLES_RADIANS    0
  96. #define ANGLES_DEGREES    1
  97.  
  98.  
  99. #if defined(AMIGA_LC_5_1) || defined(AMIGA_AC_5)
  100. #define OS "Amiga "
  101. #endif
  102.  
  103.  
  104. #ifdef vms
  105. #define OS "VMS "
  106. #endif
  107.  
  108.  
  109. #ifdef unix
  110. #define OS "unix "
  111. #endif
  112.  
  113.  
  114. #ifdef MSDOS
  115. #define OS "MS-DOS "
  116. #endif
  117.  
  118.  
  119. #ifndef OS
  120. #define OS ""
  121. #endif
  122.  
  123.  
  124. /*
  125.  * Note about VERYLARGE:  This is the upper bound double (or float, if PC)
  126.  * numbers. This flag indicates very large numbers. It doesn't have to 
  127.  * be the absolutely biggest number on the machine.  
  128.  * If your machine doesn't have HUGE, or float.h,
  129.  * define VERYLARGE here. 
  130.  *
  131.  * example:
  132. #define VERYLARGE 1e38
  133.  */
  134.  
  135. #ifdef PC
  136. #include <float.h>
  137. #define VERYLARGE FLT_MAX
  138. #else
  139. #if defined( vms ) || defined( _CRAY ) || defined( NEXT )
  140. #include <float.h>
  141. #if defined ( NEXT )  /* bug in NeXT OS 2.0 */
  142. #define DBL_MAX 1.7976931348623157e+308 
  143. #endif
  144. #define VERYLARGE DBL_MAX
  145. #else
  146. #if defined(AMIGA_AC_5) || defined(AMIGA_LC_5_1)
  147. #include <math.h>
  148. #define VERYLARGE HUGE
  149. #else
  150. #define VERYLARGE HUGE
  151. #endif
  152. #endif
  153. #endif
  154.  
  155.  
  156. #define END_OF_COMMAND (c_token >= num_tokens || equals(c_token,";"))
  157.  
  158. #ifdef vms
  159.  
  160.  
  161. #define is_comment(c) ((c) == '#' || (c) == '!')
  162. #define is_system(c) ((c) == '$')
  163.  
  164.  
  165. #else /* vms */
  166.  
  167.  
  168. #define is_comment(c) ((c) == '#')
  169. #define is_system(c) ((c) == '!')
  170.  
  171.  
  172. #endif /* vms */
  173.  
  174. /* If you don't have vfork, then undefine this */
  175. #if defined(NOVFORK) || defined(MSDOS)
  176. # undef VFORK
  177. #else
  178. # ifdef unix
  179. #  define VFORK
  180. # endif
  181. #endif
  182.  
  183. /* 
  184.  * memcpy() comes by many names. The default is now to assume bcopy, 
  185.  * since it is the most common case. Define 
  186.  *  MEMCPY to use memcpy(), 
  187.  *  vms to use the vms function,
  188.  *  NOCOPY to use a handwritten version in parse.c
  189.  */
  190. #ifdef vms
  191. # define memcpy(dest,src,len) lib$movc3(&len,src,dest)
  192. #else
  193. # if defined(MEMCPY) || defined(MSDOS)
  194.    /* use memcpy directly */
  195. # else 
  196. #  ifdef NOCOPY
  197.     /* use the handwritten memcpy in parse.c */
  198. #  else
  199.     /* assume bcopy is in use */
  200. #   define memcpy(dest,src,len) bcopy(src,dest,len)
  201. #  endif /* NOCOPY */
  202. # endif /* MEMCPY || MSDOS */
  203. #endif /* vms */
  204.  
  205. /*
  206.  * In case you have MEMSET instead of BZERO. If you have something 
  207.  * else, define bzero to that something.
  208.  */
  209. #if defined(MEMSET) || defined(MSDOS)
  210. #define bzero(dest,len)  (void)(memset(dest, (char)NULL, len))
  211. #endif /* MEMSET || MSDOS */
  212.  
  213. /* Give the name of your gamma function, or undefine it if you have none.  */
  214. #if defined(NOGAMMA) || defined(MSDOS)
  215. # undef GAMMA
  216. #else
  217. # ifndef GAMMA
  218. #  define GAMMA gamma
  219. # endif /* GAMMA */
  220. #endif /* NOGAMMA ||MSDOS */
  221.  
  222. #define top_of_stack stack[s_p]
  223.  
  224. typedef int BOOLEAN;
  225.  
  226. #ifdef __ZTC__
  227. typedef int (*FUNC_PTR)(...);
  228. #else
  229. typedef int (*FUNC_PTR)();
  230. #endif
  231.  
  232. #if defined(AMIGA_LC_5_1) || defined(AMIGA_AC_5)
  233. enum operators {
  234.     PUSH, PUSHC, PUSHD1, PUSHD2, CALL, CALL2, LNOT, BNOT, UMINUS, LOR, LAND,
  235.     BOR, XOR, BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT, DIV,
  236.     MOD, POWER, FACTORIAL, ABOOL, JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
  237. };
  238. #else
  239. enum operators {
  240.     PUSH, PUSHC, PUSHD1, PUSHD2, CALL, CALL2, LNOT, BNOT, UMINUS, LOR, LAND,
  241.     BOR, XOR, BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT, DIV,
  242.     MOD, POWER, FACTORIAL, BOOLE, JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
  243. };
  244. #endif
  245.  
  246.  
  247. #define is_jump(operator) ((operator) >=(int)JUMP && (operator) <(int)SF_START)
  248.  
  249.  
  250. enum DATA_TYPES {
  251.     INT, CMPLX
  252. };
  253.  
  254.  
  255. enum PLOT_TYPE {
  256.     FUNC, DATA, FUNC3D, DATA3D
  257. };
  258.  
  259.  
  260. enum PLOT_STYLE {
  261.     LINES, POINTS, IMPULSES, LINESPOINTS, DOTS, ERRORBARS
  262. };
  263.  
  264. enum JUSTIFY {
  265.     LEFT, CENTRE, RIGHT
  266. };
  267.  
  268. struct cmplx {
  269.     double real, imag;
  270. };
  271.  
  272.  
  273. struct value {
  274.     enum DATA_TYPES type;
  275.     union {
  276.         int int_val;
  277.         struct cmplx cmplx_val;
  278.     } v;
  279. };
  280.  
  281.  
  282. struct lexical_unit {    /* produced by scanner */
  283.     BOOLEAN is_token;    /* true if token, false if a value */ 
  284.     struct value l_val;
  285.     int start_index;    /* index of first char in token */
  286.     int length;            /* length of token in chars */
  287. };
  288.  
  289.  
  290. struct ft_entry {        /* standard/internal function table entry */
  291.     char *f_name;        /* pointer to name of this function */
  292.     FUNC_PTR func;        /* address of function to call */
  293. };
  294.  
  295.  
  296. struct udft_entry {                /* user-defined function table entry */
  297.     struct udft_entry *next_udf;         /* pointer to next udf in linked list */
  298.     char udf_name[MAX_ID_LEN+1];         /* name of this function entry */
  299.     struct at_type *at;            /* pointer to action table to execute */
  300.     char *definition;             /* definition of function as typed */
  301.     struct value dummy_values[MAX_NUM_VAR];    /* current value of dummy variables */
  302. };
  303.  
  304.  
  305. struct udvt_entry {            /* user-defined value table entry */
  306.     struct udvt_entry *next_udv; /* pointer to next value in linked list */
  307.     char udv_name[MAX_ID_LEN+1]; /* name of this value entry */
  308.     BOOLEAN udv_undef;        /* true if not defined yet */
  309.     struct value udv_value;    /* value it has */
  310. };
  311.  
  312.  
  313. union argument {            /* p-code argument */
  314.     int j_arg;                /* offset for jump */
  315.     struct value v_arg;        /* constant value */
  316.     struct udvt_entry *udv_arg;    /* pointer to dummy variable */
  317.     struct udft_entry *udf_arg; /* pointer to udf to execute */
  318. };
  319.  
  320.  
  321. struct at_entry {            /* action table entry */
  322.     enum operators index;    /* index of p-code function */
  323.     union argument arg;
  324. };
  325.  
  326.  
  327. struct at_type {
  328.     int a_count;                /* count of entries in .actions[] */
  329.     struct at_entry actions[MAX_AT_LEN];
  330.         /* will usually be less than MAX_AT_LEN is malloc()'d copy */
  331. };
  332.  
  333.  
  334. /* Defines the type of a coordinate */
  335. /* INRANGE and OUTRANGE points have an x,y point associated with them */
  336. enum coord_type {
  337.     INRANGE,                /* inside plot boundary */
  338.     OUTRANGE,                /* outside plot boundary, but defined */
  339.     UNDEFINED                /* not defined at all */
  340. };
  341.   
  342. #ifdef PC
  343. typedef float coordval;        /* memory is tight on PCs! */
  344. #else
  345. typedef double coordval;
  346. #endif
  347.  
  348. struct coordinate {
  349.     enum coord_type type;    /* see above */
  350.     coordval x, y, z;
  351.     coordval ylow, yhigh;    /* ignored in 3d */
  352. };
  353.  
  354. struct curve_points {
  355.     struct curve_points *next_cp;    /* pointer to next plot in linked list */
  356.     enum PLOT_TYPE plot_type;
  357.     enum PLOT_STYLE plot_style;
  358.     char *title;
  359.     int line_type;
  360.     int point_type;
  361.      int p_max;                    /* how many points are allocated */
  362.     int p_count;                    /* count of points in points */
  363.     struct coordinate *points;
  364. };
  365.  
  366. struct gnuplot_contours {
  367.     struct gnuplot_contours *next;
  368.     struct coordinate *coords;
  369.     int num_pts;
  370. };
  371.  
  372. struct iso_curve {
  373.     struct iso_curve *next;
  374.      int p_max;                    /* how many points are allocated */
  375.     int p_count;                    /* count of points in points */
  376.     struct coordinate *points;
  377. };
  378.  
  379. struct surface_points {
  380.     struct surface_points *next_sp;    /* pointer to next plot in linked list */
  381.     enum PLOT_TYPE plot_type;
  382.     enum PLOT_STYLE plot_style;
  383.     char *title;
  384.     int line_type;
  385.     int point_type;
  386.     int has_grid_topology;
  387.     int num_iso_read;  /* Data files only - num of isolines read from file. */
  388.     struct gnuplot_contours *contours;    /* Not NULL If have contours. */
  389.     struct iso_curve *iso_crvs;
  390. };
  391.  
  392. struct termentry {
  393.     char *name;
  394.     char *description;
  395.     unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
  396.     FUNC_PTR options,init,reset,text,scale,graphics,move,vector,linetype,
  397.         put_text,text_angle,justify_text,point,arrow;
  398. };
  399.  
  400.  
  401. struct text_label {
  402.     struct text_label *next;    /* pointer to next label in linked list */
  403.     int tag;            /* identifies the label */
  404.     double x,y,z;
  405.     enum JUSTIFY pos;
  406.     char text[MAX_LINE_LEN+1];
  407. };
  408.  
  409. struct arrow_def {
  410.     struct arrow_def *next;    /* pointer to next arrow in linked list */
  411.     int tag;            /* identifies the arrow */
  412.     double sx,sy,sz;        /* start position */
  413.     double ex,ey,ez;        /* end position */
  414.     BOOLEAN head;            /* arrow has a head or not */
  415. };
  416.  
  417. /* Tic-mark labelling definition; see set xtics */
  418. struct ticdef {
  419.     int type;                /* one of three values below */
  420. #define TIC_COMPUTED 1        /* default; gnuplot figures them */
  421. #define TIC_SERIES 2        /* user-defined series */
  422. #define TIC_USER 3            /* user-defined points */
  423.     union {
  424.        struct {            /* for TIC_SERIES */
  425.           double start, incr;
  426.           double end;        /* ymax, if VERYLARGE */
  427.        } series;
  428.        struct ticmark *user;    /* for TIC_USER */
  429.     } def;
  430. };
  431.  
  432. /* Defines one ticmark for TIC_USER style.
  433.  * If label==NULL, the value is printed with the usual format string.
  434.  * else, it is used as the format string (note that it may be a constant
  435.  * string, like "high" or "low").
  436.  */
  437. struct ticmark {
  438.     double position;        /* where on axis is this */
  439.     char *label;            /* optional (format) string label */
  440.     struct ticmark *next;    /* linked list */
  441. };
  442.  
  443. /*
  444.  * SS$_NORMAL is "normal completion", STS$M_INHIB_MSG supresses
  445.  
  446.  * printing a status message.
  447.  * SS$_ABORT is the general abort status code.
  448.  from:    Martin Minow
  449.     decvax!minow
  450.  */
  451. #ifdef    vms
  452. #include        <ssdef.h>
  453. #include        <stsdef.h>
  454. #define    IO_SUCCESS    (SS$_NORMAL | STS$M_INHIB_MSG)
  455. #define    IO_ERROR    SS$_ABORT
  456. #endif /* vms */
  457.  
  458.  
  459. #ifndef    IO_SUCCESS    /* DECUS or VMS C will have defined these already */
  460. #define    IO_SUCCESS    0
  461. #endif
  462. #ifndef    IO_ERROR
  463. #define    IO_ERROR    1
  464. #endif
  465.  
  466. /* Some key global variables */
  467. extern BOOLEAN screen_ok;
  468. extern BOOLEAN term_init;
  469. extern BOOLEAN undefined;
  470. extern struct termentry term_tbl[];
  471.  
  472. extern char *alloc();
  473. /* allocating and managing curve_points structures */
  474. extern struct curve_points *cp_alloc();
  475. extern int cp_extend();
  476. extern int cp_free();
  477. /* allocating and managing surface_points structures */
  478. extern struct surface_points *sp_alloc();
  479. extern int sp_replace();
  480. extern int sp_free();
  481. /* allocating and managing is_curve structures */
  482. extern struct iso_curve *iso_alloc();
  483. extern int iso_extend();
  484. extern int iso_free();
  485.